lib/deploy: Do post-ops when removing staged commit
authorColin Walters <walters@verbum.org>
Wed, 2 May 2018 14:33:32 +0000 (14:33 +0000)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 2 May 2018 16:22:34 +0000 (16:22 +0000)
These are further fixes based on running more of the rpm-ostree
test suite.

When dropping the staged deployment, we do need to do the
"post operations" such as bumping the sysroot mtime, so that
clients know something changed.  We also need to regenerate
the deployment refs.  And of course do a sysroot reload.

Also, add a "base cleanup" after creating a staged deployment
which also regenerates the refs.

Closes: #1570
Approved by: jlebon

src/libostree/ostree-sysroot-deploy.c
tests/installed/destructive/staged-deploy.yml

index 6f6181d794064b14fb15d3d323b25ee71beaf0a3..b21be0e96fad2c40e252d2ce3ebc10a287be5f53 100644 (file)
@@ -2143,6 +2143,25 @@ write_deployments_bootswap (OstreeSysroot     *self,
   return TRUE;
 }
 
+/* Actions taken after writing deployments is complete */
+static gboolean
+write_deployments_finish (OstreeSysroot *self,
+                          GCancellable  *cancellable,
+                          GError       **error)
+{
+  if (!_ostree_sysroot_bump_mtime (self, error))
+    return FALSE;
+
+  /* Now reload from disk */
+  if (!ostree_sysroot_load (self, cancellable, error))
+    return glnx_prefix_error (error, "Reloading deployments after commit");
+
+  if (!cleanup_legacy_current_symlinks (self, cancellable, error))
+    return FALSE;
+
+  return TRUE;
+}
+
 /**
  * ostree_sysroot_write_deployments_with_options:
  * @self: Sysroot
@@ -2173,6 +2192,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
    * now, which is mostly what this function is concerned with.
    * In the future we though should probably adapt things to keep it.
    */
+  gboolean removed_staged = FALSE;
   if (self->staged_deployment)
     {
       if (!glnx_unlinkat (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED, 0, error))
@@ -2183,6 +2203,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
 
       g_assert (self->staged_deployment == self->deployments->pdata[0]);
       g_ptr_array_remove_index (self->deployments, 0);
+      removed_staged = TRUE;
     }
   /* First new deployment; we'll see if it's staged */
   OstreeDeployment *first_new =
@@ -2231,10 +2252,22 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
             is_noop = FALSE;
         }
 
-      /* Silently do nothing if we're passed the same set of deployments */
+      /* If we're passed the same set of deployments, we don't need
+       * to drop into the rest of this function which deals with
+       * changing the bootloader config.
+       */
       if (is_noop)
         {
           g_assert (!requires_new_bootversion);
+          /* However, if we dropped the staged deployment, we still
+           * need to do finalization steps such as regenerating
+           * the refs and bumping the mtime.
+           */
+          if (removed_staged)
+            {
+              if (!write_deployments_finish (self, cancellable, error))
+                return FALSE;
+            }
           return TRUE;
         }
     }
@@ -2338,14 +2371,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
     _ostree_sysroot_emit_journal_msg (self, msg);
   }
 
-  if (!_ostree_sysroot_bump_mtime (self, error))
-    return FALSE;
-
-  /* Now reload from disk */
-  if (!ostree_sysroot_load (self, cancellable, error))
-    return glnx_prefix_error (error, "Reloading deployments after commit");
-
-  if (!cleanup_legacy_current_symlinks (self, cancellable, error))
+  if (!write_deployments_finish (self, cancellable, error))
     return FALSE;
 
   /* And finally, cleanup of any leftover data.
@@ -2739,6 +2765,13 @@ ostree_sysroot_stage_tree (OstreeSysroot     *self,
     return FALSE;
   if (!ostree_sysroot_load (self, cancellable, error))
     return FALSE;
+  /* Like deploy, we do a prepare cleanup; among other things, this ensures
+   * that a ref will be written for the staged tree.  See also
+   * https://github.com/ostreedev/ostree/pull/1566 though which
+   * adds an ostree_sysroot_cleanup_prune() API.
+   */
+  if (!ostree_sysroot_prepare_cleanup (self, cancellable, error))
+    return FALSE;
 
   ot_transfer_out_value (out_new_deployment, &deployment);
   return TRUE;
index 016fcd6afd146257399372f346ab9b6c477595fc..f946e1393d5930620c5c3b4b806074de5e2b58e4 100644 (file)
@@ -4,8 +4,19 @@
 - name: Write staged-deploy commit
   shell: |
     ostree --repo=/ostree/repo commit --parent="${commit}" -b staged-deploy --tree=ref="${commit}" --no-bindings
+    newcommit=$(ostree rev-parse staged-deploy)
+    orig_mtime=$(stat -c '%.Y' /sysroot/ostree/deploy)
     ostree admin deploy --stage staged-deploy
+    new_mtime=$(stat -c '%.Y' /sysroot/ostree/deploy)
+    assert_not_streq "${orig_mtime}" "${new_mtime}"
     test -f /run/ostree/staged-deployment
+    ostree refs | grep -E -e '^ostree/' | while read ref; do
+      if test "$(ostree rev-parse ${ref})" = "${newcommit}"; then
+        touch deployment-ref-found
+      fi
+    done
+    test -f deployment-ref-found
+    rm deployment-ref-found
   environment:
     commit: "{{ rpmostree_status['deployments'][0]['checksum'] }}"
 - include_tasks: ../tasks/reboot.yml